#ifndef IIC_H
#define IIC_H

#include "hardware.h"

#define PCLK_FREQ (24000000u)

#define IIC_MODE_SLAVE	0
#define IIC_MODE_MASTER	0

typedef struct _iic{
	uint8_t i2c_init : 1;
	uint8_t mode : 1;
	uint8_t busy : 1;
	uint8_t complete : 1;
	uint8_t write : 1;
	uint16_t addr;
	uint32_t count;
	uint32_t rsize;
	uint32_t ssize;
	uint8_t* sbuf;
	uint8_t* rbuf;
	M0P_I2C_TypeDef* i2c;
	void (*send_success_callback)(struct _iic* p);
	void (*rec_success_callback)(struct _iic* p);
}iic;

void iic_set_speed(iic* piic, uint32_t speed);

void iic_registered_send_callback(iic* piic, void (*p)(struct _iic* p));

void iic_registered_rec_callback(iic* piic, void (*p)(struct _iic* p));

uint8_t iic_transmit_master(iic* piic, uint16_t addr, uint8_t* send, uint32_t ss, uint8_t* rec, uint32_t rs);

uint8_t iic_transmit_slave(iic* piic, uint8_t* send, uint32_t ss);

#endif
